package com.agan.net.netty_tiny;

import com.agan.net.utils.ByteUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class HelloWorldClientHandler extends ChannelInboundHandlerAdapter {
    
    private int counter;

    

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {


	      //滑动窗体 递增
        for(int i=0;i<ByteUtil.tiny.length;i++){
            String temp= ByteUtil.tiny[i];
            byte[] req=temp.getBytes();
            System.out.println(req.length);
            //将上面的所有字符串作为一个消息体发送出去
            ByteBuf message = Unpooled.buffer(req.length);
            message.writeBytes(req);
            ctx.writeAndFlush(message);
            System.out.println();
        }
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        String buf = (String)msg;
        System.out.println("==================" + buf );
        System.out.println("++++++++++++++++++"+ (++counter));
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}